package com.lw.leetcode.str;

/**
 * 409. 最长回文串
 *
 * @Author liw
 * @Date 2021/5/8 14:39
 * @Version 1.0
 */
public class LongestPalindrome {

    public int longestPalindrome(String s) {
        int length = s.length();
        if (length < 2) {
            return length;
        }
        int[] arr = new int[128];

        for (int i = 0; i < length; i++) {
            arr[s.charAt(i)] += 1;
        }
        int max = 0;
        boolean flag = false;
        for (int i = 0; i < 128; i++) {
            int value = arr[i];
            if (value != 0) {
                max += value;
                if ((value & 1) != 0) {
                    max--;
                    flag = true;
                }
            }
        }
        return flag ? max + 1 : max;
    }

}
